package com.cyys.modules.system.service.param;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyys.common.ql.AR;
import com.cyys.common.services.CyysBaseService;
import com.cyys.modules.system.dao.param.ParamBasicDao;
import com.cyys.modules.system.model.param.ParamBasic;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("paramBasicService")
@Transactional(readOnly = true)
public class ParamBasicService extends CyysBaseService<ParamBasicDao, ParamBasic> {

	@Transactional(readOnly = false)
	public AR save(ParamBasic paramBasic) {
		dao.insert(paramBasic);
		return AR.ok("保存成功");
	}

	@Transactional(readOnly = false)
	public AR update(ParamBasic paramBasic, String oldId) {
		dao.update(paramBasic, oldId);
		return AR.ok("更新成功");
	}


	public Map<String,String> getSystemName(){
		Map<String,String> map = new HashMap<>();
		QueryWrapper<ParamBasic> qw = new QueryWrapper();
		qw.orderByAsc("sort");
		List<ParamBasic> paramBasicList = dao.selectList(qw);
		for (ParamBasic paramBasic : paramBasicList) {
			map.put(paramBasic.getSystemName(),paramBasic.getName());
		}
		return map;
	}

}
